package com.whw.cbf_qimodazuoye.entity;

import android.content.Context;
import android.text.TextPaint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.whw.cbf_qimodazuoye.R;

import java.util.List;

public class HotelSearchResultAdapter extends ArrayAdapter<Hotel> {
    private int resourceId;  //这个参数其实是每个item的layout

    public HotelSearchResultAdapter(@NonNull Context context, int resource, @NonNull List<Hotel> objects) {
        super(context, resource, objects);
        resourceId = resource;
    }

    public View getView(int position, View convertView, ViewGroup parent){
        Hotel hotel = getItem(position);
        View view = LayoutInflater.from(getContext()).inflate(resourceId,null);
        ImageView hotelCoverpic = (ImageView)view.findViewById(R.id.SearchhotelImage);
        TextView hotelIndex = (TextView)view.findViewById(R.id.SearchhotelIndex);
        System.out.println(hotel.getHotelCoverpic());
        hotelIndex.setText(hotel.getHotelIndex());
        TextPaint paint = hotelIndex.getPaint();
        paint.setFakeBoldText(true);
        String pic[] = hotel.getHotelCoverpic().split(";");
        Glide.with(this.getContext())
                .load(pic[1])
                //设置占位图
                .placeholder(R.mipmap.ic_launcher)
                //加载错误图
                .error(R.mipmap.ic_launcher)
                //磁盘缓存的处理
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(hotelCoverpic);
        return view;
    }
}
